<template>
	<div>
	<van-nav-bar title="京东注册" left-text="返回" left-arrow @click-left="$router.go(-1)" />

		<van-form @submit="onSubmit">
			<van-cell-group inset>
				<van-field
					v-model="telcode"
					name="telcode"
					center
					clearable
					label="短信验证码"
					placeholder="请输入短信验证码"
				>
					<template #button>
						<van-button size="small" type="primary" @click="timeout">发送验证码</van-button>
					</template>
				</van-field>
			</van-cell-group>
			
			<div style="margin: 16px;">
				<van-button round block type="primary" native-type="submit"
					color="linear-gradient(to right, #ff6034, #ee0a24)">
					下一步
				</van-button>
			</div>
		</van-form>
	</div>
</template>

<script setup lang='ts'>
import { Code,Verify } from '@/api/loginapi';
import { ref, type Ref } from 'vue';
import { useRouter,useRoute } from 'vue-router';

const route = useRoute()
console.log(route.query.tel);


// 验证码
const telcode:Ref<string> = ref('')

const router = useRouter()


const timeout = ()=>{
	Code({tel:(route.query.tel) as string}).then((res:any) => {
		console.log(res);
		if(res.code==200){
			console.log(res.data);
		}
	})
}


const onSubmit = () => {
	Verify({telcode:telcode.value,tel:(route.query.tel)  as string}).then((res:any)=>{
		console.log(res);
		if(res.code==200){
			router.push({path:'/register/step3',query:{tel:route.query.tel}})
		}
	})
}



</script>

<style scoped>

</style>